efform_onload = function ()
{  
 	efgrid.submitInqu( "ef_grid_result", "ZM","ZMCD11","query"); 
	var _info = new EiInfo();
	EiCommunicator.send("ZMCD14", "query", _info, ajax_callback1); 

	hideAndShowSubButtons(false);
};  
var ajax_callback1 = {
	onSuccess : function(eiInfo) {
		efwindow.hide(); 
		var grid = efgrid.getGridObject("ef_grid_detail");
		grid.refresh(eiInfo);
	},
	onFail : function(eMsg) {
	}
};
button_query_onclick = function () 
{   	
	efgrid.submitInqu( "ef_grid_result", "ZM","ZMCD11","query");
	clearRegion("ef_grid_detail");
	hideAndShowSubButtons(false);
}
button_update_onclick = function (){ 
	if (isSelected("ef_grid_result") == 0)return; 
	efgrid.submitForm( "ef_grid_result", "ZM","ZMCD11","update",true);
	hideAndShowSubButtons(false);
}
button_insert_onclick = function (){
	if (isSelected("ef_grid_result") == 0)return; 
	efgrid.submitForm( "ef_grid_result", "ZM","ZMCD11","insert",true);
	hideAndShowSubButtons(false);
} 
button_delete_onclick = function (){
	if (isSelected("ef_grid_result") == 0)return; 
	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		if(r)efgrid.submitForm( "ef_grid_result", "ZM","ZMCD11","delete",true);
		hideAndShowSubButtons(false);
	});
} 

efgrid_onRowClicked = function( grid_id, row_index ){
	if(grid_id == "ef_grid_result"){ 
		var grid = efgrid.getGridObject(grid_id);
		var fdKeyId=grid.getCellValueByColumnName(row_index,"fdKeyId"); 
		//隐藏/显示从表按钮 
		var info = new EiInfo();
		info.set("fdDirId",fdKeyId);  
		$('#fdDirId').val(fdKeyId); 
		hideAndShowSubButtons(true);
		EiCommunicator.send("ZMCD14", "query", info, ajax_chang_callback);  
	}
}
var ajax_chang_callback= {
	onSuccess: function(eiInfo) { 
		 efwindow.hide();
		 var grid = efgrid.getGridObject("ef_grid_detail");
		 grid.refresh(eiInfo);
	},
	onFail:function(eMsg)
	{
		EFAlert("新增失败，原因："+eMsg); 
	}
}
/********************************************************************************
 ***********************************从表操作**************************************** 
 ********************************************************************************/
button_insert1_onclick = function (){
	if (isSelected("ef_grid_detail") == 0)return; 
	efgrid.submitForm( "ef_grid_detail", "ZM","ZMCD14","insert",true);
} 
button_update1_onclick = function (){
	if (isSelected("ef_grid_detail") == 0)return; 
	efgrid.submitForm( "ef_grid_detail", "ZM","ZMCD14","update",true);
}
button_delete1_onclick = function (){
	var grid=isSelected("ef_grid_detail");
	if (grid == 0)return;  
	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		if(r){
			efgrid.submitForm( "ef_grid_detail", "ZM","ZMCD14","delete",true);
		}
	}); 
}  
efgrid_afterAddNewRow = function(grid_id){ 

	var grid = efgrid.getGridObject(grid_id);
	var rows = grid.getCheckedRows(); 
	if(grid_id=="ef_grid_detail")
	{
		var fdDirId=$('#fdDirId').val();  
		for(var i = 0 ; i < rows.length;i++){
			grid.getBlockData().setCell(rows[i], "fdKeyId", "");
			grid.getBlockData().setCell(rows[i], "fdDirId", fdDirId);
		}
	}
	if(grid_id=="ef_grid_result")
	{
		var fdSuperDirId=$('#fdSuperDirId').val(); 
		var fdDirType=$('#fdDirType').val(); 
		var fdCreatorId=$('#fdCreatorId').val(); 
		var fdCreateDepartmentId=$('#fdCreateDepartmentId').val();  
	   
		for(var i = 0 ; i < rows.length;i++){
			grid.getBlockData().setCell(rows[i], "fdKeyId", "");
			grid.getBlockData().setCell(rows[i], "fdDepartmentId", fdCreateDepartmentId);
			grid.getBlockData().setCell(rows[i], "fdCreatorId", fdCreatorId);
			grid.getBlockData().setCell(rows[i], "fdSuperDirId", fdSuperDirId);
			grid.getBlockData().setCell(rows[i], "fdDirType", fdDirType);
		}
	}
}
var hideAndShowSubButtons=function(status)
{
	if(!status)
	{
		efbutton.setButtonStatus("insert1", false);
		efbutton.setButtonStatus("update1", false);
		efbutton.setButtonStatus("delete1", false);
	}else
	{
		efbutton.setButtonStatus("insert1", true);
		efbutton.setButtonStatus("update1", true);
		efbutton.setButtonStatus("delete1", true);
	}
}